package com.statistics.scheduler;

import com.statistics.cloudpower.dao.TblEquipmentDAO;
import com.statistics.cloudpower.entity.TblEquipment;
import com.statistics.service.StatisticsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @author MәӧωρaЯsε
 * @date 2017/7/11.
 */
@Component
public class Scheduler {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private StatisticsService statisticsService;

    private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


    //每天00:01:00执行一次
    @Scheduled(cron="0 1 0 * * ?")
    public void runEveryday() throws ParseException {
        String thread_start_time = simpleDateFormat.format(new Date());
        logger.info(thread_start_time);
        logger.info("每天00:01:00执行一次");
        statisticsService.countEveryDay();
    }

    //每周星期一00:01:00执行一次
    @Scheduled(cron = "0 1 0 * * MON")
    public void runEveryWeek() throws ParseException {
        String thread_start_time = simpleDateFormat.format(new Date());
        logger.info(thread_start_time);
        logger.info("每周星期一00:01:00执行一次");
        statisticsService.countEveryWeek();
    }

    //每月1号 00:01:00执行一次
    @Scheduled(cron = "0 1 0 1 * ?")
    public void runEveryMonth(){
        String thread_start_time = simpleDateFormat.format(new Date());
        logger.info(thread_start_time);
        logger.info("每月1号 00:01:00执行一次");
        statisticsService.countEveryMonth();
    }

}
